<template>
  <div class="app-container">
    <el-descriptions title="监控与通信设施————清洁频率">
      <el-descriptions-item label="一级养护建议清洁频率">1次/季度</el-descriptions-item>
      <el-descriptions-item label="二级养护建议清洁频率">1次/半年</el-descriptions-item>
      <el-descriptions-item label="三级养护建议清洁频率">1次/年</el-descriptions-item>
    </el-descriptions>
    <hr>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <el-form-item label="隧道名称" prop="field1">
        <el-select
          v-model="queryParams.field1"
          placeholder="请选择隧道名称"
          clearable
          @keyup.enter.native="handleQuery">
          <el-option
            v-for="item in suidaoList"
            :key="item.id + ''"
            :label="item.field2"
            :value="item.field2 + ''"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备名称" prop="field4">
        <el-select v-model="queryParams.field4" placeholder="请选择设备名称" @keyup.enter.native="handleQuery" clearable>
          <el-option
            v-for="item in shebeiname"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-form-item label="养护等级">
          <el-input
            v-model="queryParams.field30"
            placeholder="隧道养护等级"
            clearable
            disabled=""
            size="small"
            @keyup.enter.native="handleQuery"
          ></el-input>
        </el-form-item>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:jidiansheshiqingjieweihu:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          v-if="false"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:jidiansheshiqingjieweihu:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          v-if="false"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:jidiansheshiqingjieweihu:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:jidiansheshiqingjieweihu:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="jidiansheshiqingjieweihuList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column label="清洁维护单号" align="center" prop="id" />
      <el-table-column label="隧道名称" align="center" prop="field1" />
      <el-table-column label="设备名称" align="center" prop="field4" />
      <el-table-column label="养护机构" align="center" prop="field2" />
      <el-table-column label="养护日期" align="center" prop="field3" />
      <el-table-column label="清洁措施" align="center" prop="field5" />
<!--      <el-table-column label="养护状态" align="center" prop="field6" />-->
      <el-table-column label="养护人员" align="center" prop="field7" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:jidiansheshiqingjieweihu:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:jidiansheshiqingjieweihu:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或编辑/查看清洁维护对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="40%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="隧道名称" prop="field1">
          <el-select v-model="form.field1" placeholder="请选择隧道名称" clearable>
            <el-option
              v-for="dict in suidaoList"
              :key="dict.id + ''"
              :label="dict.field2"
              :value="dict.field2 + ''"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="养护机构" prop="field2">
          <el-input v-model="form.field2" placeholder="请输入养护机构" clearable/>
        </el-form-item>
        <el-form-item label="养护日期" prop="field3">
          <el-input v-model="form.field3" placeholder="请输入养护日期" clearable/>
        </el-form-item>
        <el-form-item label="设备名称" prop="field4">
          <el-select v-model="form.field4" placeholder="请选择设备名称" clearable>
            <el-option
              v-for="item in shebeiname"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="清洁措施" prop="field5">
          <el-input v-model="form.field5" placeholder="请输入清洁措施" clearable/>
        </el-form-item>
        <el-form-item label="养护人员" prop="field6">
          <el-input v-model="form.field6" placeholder="请输入养护人员" clearable/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入内容" clearable/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listJidiansheshiqingjieweihu,
  getJidiansheshiqingjieweihu,
  delJidiansheshiqingjieweihu,
  addJidiansheshiqingjieweihu,
  updateJidiansheshiqingjieweihu,
  exportJidiansheshiqingjieweihu,
} from "@/api/biz/jidiansheshiqingjieweihu";
import { listSuidao } from "@/api/biz/suidao";
import { listShebei } from "@/api/biz/shebei";

export default {
  name: "Jidiansheshiqingjieweihu",
  data() {
    return {
      shebeiname:[
        {
           value: '射流风机',
           label: '射流风机'
        }, {
           value: '轴流风机',
           label: '轴流风机'
        },
      ],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      suidaoList: [],
      // 设备管理表格数据
      shebeiList: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 清洁维护表格数据
      jidiansheshiqingjieweihuList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
        field7: null,
        field8: null,
        field9: null,
        field10: null,
        field11: null,
        field12: null,
        field13: null,
        field14: null,
        field15: null,
        field16: null,
        field17: null,
        field18: null,
        field19: null,
        field20: null,
        field21: null,
        field22: null,
        field23: null,
        field24: null,
        field25: null,
        field26: null,
        field27: null,
        field28: null,
        field29: null,
        field30: null,
        type: null,
        num: null,
        status: null,
        date1: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        field1: [
          { required: true, message: "隧道名称不能为空", trigger: "blur" },
        ],
        field2: [
          { required: true, message: "养护机构不能为空", trigger: "blur" },
        ],
        field3: [
          { required: true, message: "养护日期不能为空", trigger: "blur" },
        ],
        field4: [
          { required: true, message: "设备名称不能为空", trigger: "blur" },
        ],
        field5: [
          { required: true, message: "清洁措施不能为空", trigger: "blur" },
        ],
        field6: [
          { required: true, message: "养护人员不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    listSuidao({}).then((response) => {
      this.suidaoList = response.rows;
    });
  },
  methods: {
    /** 查询清洁维护列表 */
    getList() {
      this.loading = true;
      listJidiansheshiqingjieweihu(this.queryParams).then((response) => {
        this.jidiansheshiqingjieweihuList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        field5: null,
        field6: null,
        field7: null,
        field8: null,
        field9: null,
        field10: null,
        field11: null,
        field12: null,
        field13: null,
        field14: null,
        field15: null,
        field16: null,
        field17: null,
        field18: null,
        field19: null,
        field20: null,
        field21: null,
        field22: null,
        field23: null,
        field24: null,
        field25: null,
        field26: null,
        field27: null,
        field28: null,
        field29: null,
        field30: null,
        type: null,
        num: null,
        status: "0",
        date1: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加机电设施清洁维护";
    },
    /** 编辑/查看按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getJidiansheshiqingjieweihu(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改机电设施清洁维护";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateJidiansheshiqingjieweihu(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJidiansheshiqingjieweihu(this.form).then((response) => {
              this.$modal.msgSuccess("添加成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delJidiansheshiqingjieweihu(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal
        .confirm("是否确认导出所有机电设施清洁维护数据项？")
        .then(() => {
          this.exportLoading = true;
          return exportJidiansheshiqingjieweihu(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
